package com.totcy.atom.presenter;

import android.content.Context;

import com.totcy.atom.bean.PaperBean;
import com.totcy.atom.model.PaperModel;
import com.totcy.atom.presenter.contract.PaperContract;
import com.totcy.baselibrary.base.mvpbase.BasePresenterImpl;

import java.util.List;

/**
 * description :  Paper Presenter
 *
 * @author : Totcy
 * @date : 2018/11/8 13:35
 */
public class PaperPresenter extends BasePresenterImpl<PaperContract.View, PaperContract.Model> implements PaperContract.Presenter {

    public PaperPresenter(Context context) {
        super(context);
    }

    @Override
    public PaperContract.Model attachModel() {
        return new PaperModel(mContext);
    }

    @Override
    public void getPaperList(String subjectName, int type) {
        if (isModelAttached()) {
            getModel().getPaperList(subjectName, type, new PaperContract.Model.DataCallback() {
                @Override
                public void onPaperList(List<PaperBean> papers) {
                    if (isViewAttached()) {
                        getView().onPaperList(papers);
                    }
                }

                @Override
                public void onDataNotAvailable(int code, String message) {
                    if (isViewAttached()) {
                        getView().onFail(code, message);
                    }
                }
            });
        }
    }

}
